package com.employ.job.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.employ.common.utils.DateUtils;
import com.employ.job.domain.EmpResumes;
import com.employ.job.mapper.EmpResumesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.employ.job.mapper.EmpStudentsMapper;
import com.employ.job.domain.EmpStudents;
import com.employ.job.service.IEmpStudentsService;

/**
 * 学生Service业务层处理
 *
 * @author ruoyi
 * @date 2025-02-24
 */
@Service
public class EmpStudentsServiceImpl implements IEmpStudentsService {
    @Autowired
    private EmpStudentsMapper empStudentsMapper;

    @Autowired
    private EmpResumesMapper empResumesMapper;

    /**
     * 查询学生
     *
     * @param userId 学生主键
     * @return 学生
     */
    @Override
    public EmpStudents selectEmpStudentsByUserId(Long userId) {
        EmpStudents empStudents = empStudentsMapper.selectEmpStudentsByUserId(userId);

        EmpResumes empResumesMap = empResumesMapper.selectEmpByUserId(empStudents.getUserId());
        if (empResumesMap != null) {
            empStudents.setFilePath(empResumesMap.getFilePath());
        }
        return empStudents;

    }

    /**
     * 查询学生列表
     *
     * @param empStudents 学生
     * @return 学生
     */
    @Override
    public List<EmpStudents> selectEmpStudentsList(EmpStudents empStudents) {
        List<EmpStudents> empStudentsList = empStudentsMapper.selectEmpStudentsList(empStudents);
        empStudentsList.stream().map(EmpStudents -> {
                    EmpResumes empResumesMap = empResumesMapper.selectEmpByUserId(EmpStudents.getUserId());
                    if (empResumesMap != null) {
                        EmpStudents.setFilePath(empResumesMap.getFilePath());
                    }
                    return EmpStudents;
                })
                .collect(Collectors.toList());
        return empStudentsList;
    }

    /**
     * 新增学生
     *
     * @param empStudents 学生
     * @return 结果
     */
    @Override
    public int insertEmpStudents(EmpStudents empStudents) {
        empStudents.setCreateTime(DateUtils.getNowDate());
        return empStudentsMapper.insertEmpStudents(empStudents);
    }

    /**
     * 修改学生
     *
     * @param empStudents 学生
     * @return 结果
     */
    @Override
    public int updateEmpStudents(EmpStudents empStudents) {
        empStudents.setUpdateTime(DateUtils.getNowDate());
        return empStudentsMapper.updateEmpStudents(empStudents);
    }

    /**
     * 批量删除学生
     *
     * @param userIds 需要删除的学生主键
     * @return 结果
     */
    @Override
    public int deleteEmpStudentsByUserIds(Long[] userIds) {
        return empStudentsMapper.deleteEmpStudentsByUserIds(userIds);
    }

    /**
     * 删除学生信息
     *
     * @param userId 学生主键
     * @return 结果
     */
    @Override
    public int deleteEmpStudentsByUserId(Long userId) {
        return empStudentsMapper.deleteEmpStudentsByUserId(userId);
    }
}
